#include "tpm_cipher.h"
#include "platform.h"
#include "indicate.h"
#include "stdio.h"
#include "string.h"


void tpm_cipher_sha1Test() {
    char message[] = "abc";
    UINT32 res[5];
    int i;
    printf("\nTestSha1\n");
	tpm_cipher_doSHA1((UINT8 *)message, strlen(message), res);
    for(i = 0; i < 5; i++)
        printf("%X ", res[i]);
    printf("\nShould Match\nA9993E36 4706816A BA3E2571 7850C26C 9CD0D89D\n");
}


void tpm_cipher_aes128Test() {
    const int count = 16;
    UINT8 key[count];
    UINT8 plainText[count], cipherText[count];
    int i;
    printf("\nTestAES\n");
	for(i = 0; i < count; i++) {
        plainText[i] = (UINT8)(i * 16 + 1);
    }
    printf("The plainText is: \n");
    for(i = 0; i < count; i++) {
        printf("%02x", plainText[i]);
    }
    tpm_cipher_generateAESKey128(key);
    printf("\nThe key is: \n");
    for(i = 0; i < count; i++) {
        printf("%02x", key[i]);
    }
    tpm_cipher_AESEncipher128(plainText, key, cipherText);
    printf("\nThe cipherText is: \n");
    for(i = 0; i < count; i++) {
        printf("%02x", cipherText[i]);
    }
	printf("\n");
}

void tpm_cipher_test() {
    tpm_cipher_sha1Test();
    tpm_cipher_aes128Test();
}
